package com.laviedesfons.jhmtasc.types.internals;

import com.laviedesfons.jhmtasc.annotations.binding.MType;
import com.laviedesfons.jhmtasc.exceptions.MException;
import com.laviedesfons.jhmtasc.types.interfaces.InternalType;
import fr.x9c.cadmium.kernel.Value;

/**
 *
 * @author Romano
 */
@MType
public final class PVoid implements InternalType {
    private int flagId;

    @Override
    public PVoid fromValue(Value v) throws MException {
        if(v.isLong()){
            this.flagId = v.asLong();
            return this;
        }
        throw new MException("unable to retrieve id of PVoid");
    }

    @Override
    public Value toValue() {
        return Value.createFromLong(flagId);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PVoid other = (PVoid) obj;
        if (this.flagId != other.flagId) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + this.flagId;
        return hash;
    }

    @Override
    public String toString(){
        return "PVoid";
    }
}